<template>
  <div class="app-container">
    <div class="app-main" v-if="!bindCompanyShow">
      <div class="mainName">监测公司绑定-查询</div>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="白蚁防治公司" prop="controlName">
          <el-input
            v-model="queryParams.controlName"
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="监测公司" prop="monitorName">
          <el-input
            v-model="queryParams.monitorName"
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >查询</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="assetList" border stripe>
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column
          label="序号"
          align="center"
          type="index"
          :index="indexMethod"
        >
        </el-table-column>
        <el-table-column label="监测公司" align="center" prop="monitorName" />
        <el-table-column
          label="白蚁防治公司"
          align="center"
          prop="controlName"
        />
        <el-table-column label="账号" align="center" prop="accountNumber" />
        <el-table-column
          label="设备数量"
          align="center"
          prop="devicesNumber"
          width="220"
        />

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="230"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="seedetail(scope.row)"
              >详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        class="pagination-container"
      />
    </div>
    <div class="app-main" v-if="bindCompanyShow">
      <div class="mainName">监测公司绑定→详情</div>
      <div class="btnGroupLeft">
        <el-button type="primary" @click="callBack" size="small"
          >返回</el-button
        >
      </div>
      <div class="formBox">
        <div class="formHead">详情</div>
        <div class="formWhite">
          <div class="left">监测公司</div>
          <div class="right">
            {{ submitForm.monitorName }}
            <!-- <el-select
              v-model="submitForm.jcCompany"
              size="small"
              placeholder="请选择"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select> -->
          </div>
        </div>
        <div class="formGray">
          <div class="left">白蚁防治公司</div>
          <div class="right">
            {{ submitForm.controlName }}
            <!-- <el-input
              v-model="submitForm.account"
              placeholder="请输入"
              size="small"
            ></el-input> -->
          </div>
        </div>
        <div class="formWhite">
          <div class="left">账号</div>
          <div class="right">
            {{ submitForm.accountNumber }}
            <!-- <el-input
              v-model="submitForm.password"
              placeholder="请输入"
              size="small"
            ></el-input> -->
          </div>
        </div>
        <div class="formGray">
          <div class="left">设备数量</div>
          <div class="right">
            {{ submitForm.devicesNumber }}
            <!-- <el-input
              v-model="submitForm.ssCompany"
              placeholder="请输入"
              size="small"
            ></el-input> -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getMonitorCompany
} from "@/api/manage/asset";
import { getPersonnelList } from "@/api/manage/personnel";
import { getDepartmentList } from "@/api/manage/department";
// import { treeSelect } from "@/api/system/dept";
import { getUserlist } from "@/api/system/user";
// import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "CompanySearch",
  dicts: [
    // "asset_unit",
    // "asset_acquisition_method",
    // "asset_use_status",
    // "asset_use_direction",
  ],
  // components: { Treeselect, printDSVue },
  data() {
    return {
      bindCompanyShow: false,
      submitForm: {},
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产信息表格数据
      assetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 资产分类树桩选项
      assetClassificationOptions: [],
      // 启用日期时间范围
      daterangeStartDate: [],
      // 部门树桩选项
      deptOptions: [],
      // 归属账号下拉选项
      listUsers: [
        {
          value: "行政区一",
          label: "行政区一",
        },
        {
          value: "行政区二",
          label: "行政区二",
        },
        {
          value: "行政区三",
          label: "行政区三",
        },
      ],
      // 是否显示二维码弹出层
      getCodeUrlOpen: false,
      // 打印弹出层
      openPrint: false,
      assets: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        monitorName: "",
        controlName: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // accountNumber: [
        //   { required: true, message: "资产名称不能为空", trigger: "blur" },
        // ],
      },
      // 导入结果弹出框
      resultVisible: false,
      // 人员下拉
      personnels: [],
      // 部门下拉
      departments: [],
    };
  },
  created() {
    this.getList();
    
  },
  methods: {
    callBack() {
      this.bindCompanyShow = false;
    },
    indexMethod(index) {
      return index + 1;
    },
    seedetail(row) {
      console.log(row);
      this.submitForm = row;
      this.bindCompanyShow = true;
    },
    /*人员下拉选项*/
    getDepartment() {
      getDepartmentList().then((response) => {
        this.departments = response.rows;
      });
    },
    /*人员下拉选项*/
    getPersonnel() {
      getPersonnelList().then((response) => {
        this.personnels = response.rows;
      });
    },

    /** 二维码按钮操作 */
    getCodeUrl(row) {
      this.reset();
      this.getCodeUrlOpen = true;
      this.title = "rfid编码（" + row.rfidCode + ")";
      // 生成二维码
      this.$nextTick(function () {
        console.log(document.getElementById("qrCodeUrl"));
        document.getElementById("qrCodeUrl").innerHTML = "";
        let qrCodeUrl = new QRCode("qrCodeUrl", {
          width: 200,
          height: 200,
          text: row.rfidCode,
          colorDark: "#000000",
          colorLight: "#fff",
        });
      });
    },
    /** 查询资产信息列表 */
    getList() {
      this.loading = true;
      getMonitorCompany(this.queryParams).then(res =>{
        if(res.errorCode == '000000') {
          this.assetList = res.data.list;
          this.total = res.data.total;
        }
      }).finally(() =>{
        this.loading = false;
      })
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        accountNumber: null,
        devicesNumber: null,
      };
      this.resetForm("form");
      this.openPrint = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.reset();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset();
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除资产信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delAsset(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.app-main {
  background-color: #fff;
  // padding: 15px 20px;
  border-radius: 8px;
  .mainName {
    font-family:
      PingFangSC,
      PingFang SC;
    font-weight: 500;
    font-size: 16px;
    height: 30px;
    line-height: 30px;
    color: #000000;
    border-bottom: 1px solid #dcdfe6;
    margin-bottom: 10px;
  }
  .btnGroupLeft {
    text-align: left;
    margin: 15px 0;
  }
  .formBox {
    .left {
      display: inline-block;
      height: 44px;
      line-height: 44px;
      width: 100px;
      padding-right: 15px;
      border-left: 1px solid #e4e4dc;
      border-right: 1px solid #e4e4dc;
      font-family: MicrosoftYaHei;
      font-size: 12px;
      color: #303133;
      text-align: right;
      vertical-align: top;
    }
    .right {
      display: inline-block;
      width: calc(100% - 100px);
      height: 44px;
      line-height: 32px;
      font-family:
        PingFangSC,
        PingFang SC;
      font-weight: 400;
      font-size: 12px;
      color: #303133;
      border-right: 1px solid #e4e4dc;
      padding: 6px 15px;
      .el-select {
        width: 340px !important;
      }
      .el-input {
        width: 340px !important;
      }
    }
    .formHead {
      width: 100%;
      height: 44px;
      background-color: #5d6d7f;
      height: 44px;
      line-height: 44px;
      text-align: center;
      font-family: MicrosoftYaHei, MicrosoftYaHei;
      font-weight: bold;
      font-size: 12px;
      color: #ffffff;
    }
    .formWhite {
      width: 100%;
      height: 44px;
      background-color: #fff;
    }
    .formGray {
      width: 100%;
      height: 44px;
      background-color: #dbe2e6;
    }
  }
}
.el-collapse .el-collapse-item__header {
  font-size: 16px;
  font-weight: bold;
}

.pagination-container {
  margin-top: 20px;
  width: 100%;
}

.pagination-container .el-pagination {
  display: flex;
  justify-content: center;
  width: 100%;
}
</style>
